package com.enniswu.weitter.browse;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.enniswu.weitter.R;
import com.enniswu.weitter.base.BaseActivity;

import java.util.List;

import butterknife.BindView;

import static android.support.v4.view.ViewPager.SCROLL_STATE_DRAGGING;
import static android.support.v4.view.ViewPager.SCROLL_STATE_IDLE;

public class BrowseActivity extends BaseActivity implements ViewPager.OnPageChangeListener {

    @BindView(R.id.tv_indicator)
    TextView tvIndicator;
    @BindView(R.id.vp_browse)
    ViewPager vpBrowse;
    private List<String> album;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_browse);
        album = (List<String>) getIntent().getSerializableExtra("album");
        vpBrowse.addOnPageChangeListener(this);
        vpBrowse.setAdapter(new BrowseAdapter(this, album));
        vpBrowse.setCurrentItem(
                getIntent().getIntExtra("position", 0), false);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        tvIndicator.setText(position + 1 + "/" + album.size());
    }

    @Override
    public void onPageScrollStateChanged(int state) {
        if (state == SCROLL_STATE_DRAGGING || state == SCROLL_STATE_IDLE) {
            tvIndicator.setVisibility(View.INVISIBLE);
        } else {
            tvIndicator.setVisibility(View.VISIBLE);
        }
    }
}
